--第四节 条件分支与循环

local UnitlModule = require("Lua.UnitlModule");

--#region  4.1 条件分支

--if {Condition} then {ToDo} end
--Lua 里面没有Switch

UnitlModule.PrintTimer();

UnitlModule.PrintOperaName("***条件分支部分***");
local a = 9;
--单分支
UnitlModule.PrintOperaName("单分支");

if a > 5 then
    print("a > 5\n");
end

--双分支
UnitlModule.PrintOperaName("双分支");
if a > 6 then
    print("a > 6\n");
else    
    print("a > 6 is not !\n");
end

--多分支
UnitlModule.PrintOperaName("多分支");
if a > 6 then
    print("a > 6\n");
elseif a + 3 == 9 then
    print("a +3 == 9\n");

else    
    print("a > 6 is not !\n");
end

--#endregion



--#region 4.2循环
UnitlModule.PrintTimer();
UnitlModule.PrintOperaName("***循环部分***");

local num = 0;

UnitlModule.PrintOperaName("while语句");
while num < 10 do
    num = num + 1;
end
print("num is "..num);
num = 0;

UnitlModule.PrintOperaName("do...while语句");
repeat
    num = num + 1;
until num > 5
print("num is "..num);
num = 0;


UnitlModule.PrintOperaName("for语句");
for i = 1,5,1 do
    print(i.." ");
end

for i = 1,5,2 do
    print(string.format("%d",i));
end

for i = 5,1,-1 do
    print(i.." ");
end
--#endregion